package managers.positionManager.addTask;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import junit.framework.TestCase;

import org.apache.log4j.Logger;
import org.tbjd.client.beans.Task;
import org.tbjd.client.constants.NotificationsConstants;
import org.tbjd.client.exceptions.TaskManagerException;
import org.tbjd.client.managers.TaskManager;
import org.tbjd.client.mediators.ChiefMediator;

/**
 * <p>
 * Test TaskManager's methods
 * </p>
 * <p>
 * <b> Case</b>
 * <p>
 * A task which has multiple predecessors and those predecessors should update the task but we want the task to be updated just once
 * </p>
 * </p>
 * <p>
 * <b>Action</b>
 * </p>
 * <p>
 * BeginDate of a predecessor task is changed
 * </p>
 * <p>
 * <b> Expected</b>
 * <ul>
 * <li>update EndDate of "task"</li>
 * <li>set manual chainingMode for "task"</li>
 * <li>update successors dates</li>
 * <li>avoid multiple updates on the same successor</li>
 * </ul>
 * </p>
 * 
 * <b>
 * 		Don't forget to comment the <code> ProjectsGridDecorator projectsGridDecorator = new ProjectsGridDecorator(); </code> line in the {@link org.tbjd.client.mediators.ChiefMediator ChiefMediator}
 * </b>
 * @author Michael Martin
 * @author Antonio Carrozzini
 * @version 1.0
 * 
 */

public class Add_Task_Basic extends TestCase {

	/*
	 * Task		Begins 		Ends 		Successor 	ChainingMode	task +2 days
	 */

	private Map<Integer, Object> map = null;
	private Logger log = Logger.getLogger("console");
	private TaskManager taskManager = new TaskManager();

	protected void setUp() throws Exception {
		
		map = new HashMap<Integer, Object>();

		map.put(NotificationsConstants.TASKMANAGER_ACTION_add, null);
		map.put(NotificationsConstants.TASK_ADDED, null);
		map.put(NotificationsConstants.TASK_LEVEL, -1);

		super.setUp();
	}
	
	@Override
	protected void tearDown() throws Exception {

		ChiefMediator.resetInstance();
		
		super.tearDown();
	}

	/*
	 * Task					Parent 		Level 		Type		Children
	 * untitled task		null		1			Task		null
	 */
	public void testResultNotNull() {
		System.out.println("");
		log.debug(" === testResultNotNull");

		try {
			assertNotNull(taskManager.managePositions(map));

		} catch (TaskManagerException e) {
			fail(e.getMessage());

		}

	}
	
	/*
	 * Task					Parent 		Level 		Type		Children
	 * untitled task		null		1			Task		null
	 */
	public void testResultSize() {
		System.out.println("");
		log.debug(" === testResultSize");

		try {
			assertEquals(1, taskManager.managePositions(map).size());

		} catch (TaskManagerException e) {
			fail(e.getMessage());

		}

	}
	
	/*
	 * Task					Parent 		Level 		Type		Children
	 * untitled task		null		1			Task		null
	 */
	public void testLevel() {
		System.out.println("");
		log.debug(" === testLevel");

		try {
			
			List<Task> lstBeans = taskManager.managePositions(map);
			
			assertEquals(0, lstBeans.get(0).getLevel());

		} catch (TaskManagerException e) {
			fail(e.getMessage());

		}

	}
	
	
	public void testTypeTask(){
		
		System.out.println("");
		log.debug(" === testTypeTask");

		try {
			map.put(NotificationsConstants.TASKMANAGER_ACTION_add, null);
			map.put(NotificationsConstants.TASK_ADDED, null);
			map.put(NotificationsConstants.TASK_LEVEL, -1);
			
			List<Task> lstBeans = taskManager.managePositions(map);
			
			assertEquals(Task.TASK, lstBeans.get(0).getType());

		} catch (TaskManagerException e) {
			fail(e.getMessage());

		}

		
		
		
	}

	
	
	

}